/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 
 * @author Ahmad 'ANS' Syuhada
 */
import java.sql.*;

public class dbcon {
    private Connection con = null;
    private Statement st = null;
    private ResultSet rs = null;
    /**
     * @param args the command line arguments
     */
    public dbcon(String db, String user, String pass) {
        try {
            this.con = DriverManager.getConnection("jdbc:mysql://localhost/"+db,user,pass);
        } catch (SQLException ex) {
            System.out.println("Exception motherfucker! "+ex);
        }
    }
    public ResultSet dbQuery(String query) {
        // for select
        this.rs = null;
        try {
            this.st = con.createStatement();
            this.rs = st.executeQuery(query);
        } catch (SQLException ex) {
            System.out.println("Exception motherfucker! "+ex);
        }
        return this.rs;
    }
    public int dbUpdate(String query) {
        // for insert, update
        int retval;
        try {
            this.st = con.createStatement();
            retval = st.executeUpdate(query);
        } catch (SQLException ex) {
            retval = -1;
            System.out.println("Exception motherfucker! "+ex);
        }
        return retval;
    }
}
